﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SpriteAnimator.Classes
{
    /// <summary>
    /// Défini une séquence d'animation
    /// </summary>
    public class SpriteSequence: IComparable<SpriteSequence>, ICloneable
    {
        #region Constructeurs

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        /// <param name="p_sName">Nom de la séquence</param>
        public SpriteSequence(string p_sName)
        {
            this.Name = p_sName;
            this.Type = SpriteAnimationType.None;
            this.FramesIndexes = new List<int>();
        }

        #endregion

        #region Fonctions publiques

        /// <summary>
        /// Génère le rapport d'état de l'animation
        /// </summary>
        /// <returns>Rapport généré</returns>
        public string GenerateRapport()
        {
            StringBuilder oGen = new StringBuilder();

            // *** Génération ***

            oGen.Append(String.Format("Nom : {0}\n", this.Name));
            oGen.Append(String.Format("Type : {0}\n", this.Type));
            oGen.Append(String.Format("Total frames : {0}\n", this.FramesIndexes.Count));

            // *** On reoturne la génération ***

            return (oGen.ToString());
        }

        /// <summary>
        /// Retourne la classe en expression texte
        /// </summary>
        /// <returns>Expression texte</returns>
        public override string ToString()
        {
            return (this.Name);
        }

        #endregion

        #region IComparable<SpriteSequence> Members

        /// <summary>
        /// Compare deux instances
        /// </summary>
        /// <param name="other">Autre instance</param>
        /// <returns>Indicateur de comparaison</returns>
        public int CompareTo(SpriteSequence other)
        {
            return (this.Name.CompareTo(other.Name));
        }

        #endregion

        #region ICloneable Members

        /// <summary>
        /// Clone l'instance
        /// </summary>
        /// <returns>Clone généré</returns>
        object ICloneable.Clone()
        {
            return (this.Clone());
        }

        /// <summary>
        /// Clone l'instance
        /// </summary>
        /// <returns>Clone généré</returns>
        public virtual SpriteSequence Clone()
        {
            SpriteSequence oClone = this.MemberwiseClone() as SpriteSequence;

            oClone.FramesIndexes = new List<int>();

            foreach ( int oIndex in this.FramesIndexes )
                oClone.FramesIndexes.Add(oIndex);

            return (oClone);
        }

        #endregion

        #region Indexer

        /// <summary>
        /// Retourne la liste des frames pour cette séquence
        /// </summary>
        public List<int> FramesIndexes
        {
            get;
            private set;
        }

        /// <summary>
        /// Nom de la séquence
        /// </summary>
        public string Name
        {
            get;
            set;
        }

        /// <summary>
        /// Type de la séquence
        /// </summary>
        public SpriteAnimationType Type
        {
            get;
            set;
        }

        #endregion
    }
}
